package com.jiancong.controller;

import com.jiancong.domain.ResponseResult;
import com.jiancong.domain.dto.AddArticleDto;
import com.jiancong.domain.entity.Article;
import com.jiancong.domain.entity.Category;
import com.jiancong.domain.vo.ArticleAndTas;
import com.jiancong.domain.vo.ArticleVo;
import com.jiancong.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article){
        return articleService.add(article);
    }

    @GetMapping("/list")
    public ResponseResult getArticles(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      ArticleVo articlevo)
    {
        return articleService.getArticles(pageNum,pageSize,articlevo);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleDetails(@PathVariable("id") Long id) {
        // 根据 ID 查询文章详情
        ArticleAndTas articleAndTas = articleService.getArticleDetailById(id);
            return ResponseResult.okResult(articleAndTas);
        }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody AddArticleDto article) {
        // 更新文章
        return articleService.updateArticle(article);

    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        return articleService.deleteArticle(id);
    }

}
